//
//  StringVC.swift
//  Example
//
//  Created by remy on 2019/11/15.
//  Copyright © 2019 com.Risac. All rights reserved.
//

class StringVC: BaseVC {
    override func viewDidLoad() {
        super.viewDidLoad()
        topBarView.centerItem = .text(title)
        let label1 = UILabel(frame: CGRect(x: 16.0, y: Size.topHeight + 16.0, width: Size.screenWidth - 32.0, height: 0.0), textColor: FlatColor.sunflower, fontSize: 15.0, bold: true, bgColor: FlatColor.midnightBlue, alignment: .center)
        label1.numberOfLines = 0
        // MARK: 设置行高时,同一行没有其他不同baseline的文本时设置baseline<0不生效
        // MARK: 未设置行高时,设置baseline多行布局错乱
        let attr1 = "baseline<0生效".sac.line(height: 30.0).baseline(-5.0) + " 未设置baseline".sac.line(height: 15.0) + "\nbaseline<0不生效".sac.line(height: 15.0).baseline(-5.0)
        label1.attributedText = attr1.rawValue
        label1.sizeToFit()
        self.view.addSubview(label1)
        let label2 = UILabel(frame: CGRect(x: 16.0, y: label1.bottom + 16.0, width: Size.screenWidth - 32.0, height: 0.0), textColor: FlatColor.sunflower, fontSize: 15.0, bold: true, bgColor: FlatColor.midnightBlue, alignment: .center)
        label2.numberOfLines = 0
        // UILabel先设置宽度,富文本alignment设置为.right后再sizeToFit,宽度已经改变
        let attr2 = "第一行🍖".sac.line(height: 30.0) + "\n第二行🍋".sac.line(height: 30.0).baseline(5.0) + "\n第三行🍕".sac.line(height: 30.0) + "\n第四行🍙".sac.line(height: 30.0, alignment: .right)
        label2.attributedText = attr2.rawValue
        label2.sizeToFit()
        self.view.addSubview(label2)
        let attr3 = "1111 2222222 3333333".sac.line(height: 30.0).systemFont(20.0) + "4444 5555 666 7777777 88888888".sac.line(height: 20.0).systemFont(14.0)
        let label3 = UILabel(frame: CGRect(x: 16.0, y: label2.bottom + 16.0, width: 100.0, height: 0.0), textColor: FlatColor.sunflower, bgColor: FlatColor.midnightBlue, alignment: .center)
        label3.numberOfLines = 0
        label3.attributedText = attr3.rawValue
        label3.sizeToFit()
        self.view.addSubview(label3)
        // 测试
        Risac.print(attr3.string.sac.height(100.0, font: UIFont.systemFont(ofSize: 14.0), lineHeight: 20.0))
        Risac.print(attr3.height(100.0))
        Risac.print(attr3.systemFont(30.0).height(100.0))
        Risac.print(attr3.string.sac.width(font: UIFont.systemFont(ofSize: 14.0)))
        Risac.print(attr3.width())
        Risac.print("width计算最大宽度,height计算给定宽度的最大高度,size计算给定size内的最大size".sac.size(CGSize(width: .greatestFiniteMagnitude, height: 100.0), font: UIFont.systemFont(ofSize: 14.0), lineHeight: 20.0))
        Risac.print(WeakBox(UIView()) == WeakBox(UIView()))
        Risac.print("12345".substring(to: 0))
        Risac.print("12345".substring(to: 1))
        Risac.print("12345".substring(to: -100))
        Risac.print("12345".substring(loc: 2, len: 100))
        Risac.print("12345".substring(to: 100))
        Risac.print("12345".substring(from: -1))
        // 正则
        let regex: Regex = #"[a-z]+([0-9]+)"#
        Risac.print(regex ~= "123vvv45ddd")
        Risac.print("cccppp" ~= regex)
        let str = "3f5g3n33"
        Risac.print(regex.match(str))
        Risac.print(regex.result(str))
        Risac.print(regex.stringResult(str))
    }
}
